<?php

require './confg.php';

$result = mysqli_query($con,"SELECT password FROM members where username='$_POST[username]'") or die(mysqli_error($con));
$rowdata = mysqli_fetch_array($result);
if (md5($_POST['password']) == $rowdata['password']) {   

	if (isset($_POST['rememberme'])) {
		setcookie('username', $_POST['username'], time()+60*60*24*365);
		setcookie('password', md5($_POST['password']), time()+60*60*24*365);
	} else {
		setcookie('username', $_POST['username'], false);
		setcookie('password', md5($_POST['password']), false);
		echo "done";
	}
	header('Location: admin.php');
} else {
	echo '<script type="text/javascript">alert ("Wrong username or password, try again");window.location="login.html" </script>';
}

if(isset($_GET['logout']) && ($_GET['logout'] == true)  ){
	setcookie("username", "", time()-3600);
	setcookie("password", "", time()-3600);
	header('Location: login.html');
}
?>